from module.const.Constant import const
from module.thread.DataSimulatThread import DataSimulatThread
from module.thread.StrategyThread import StrategyThread

import logging
log = logging.getLogger("tasklog")

class ThreadManager(object):
    def __init__(self, taskcenter):
        self.taskCenter = taskcenter

    def assignTask(self):
        try:
            wokerFirst = DataSimulatThread(self.taskCenter)
            wokerFirst.start()

            wokerSecond = StrategyThread(self.taskCenter)
            wokerSecond.start()

            # 策略任务已经启动
            self.taskCenter[1] = const.TASK_STATUS_RUNNING
            log.error("任务已进行推送与监控分派 任务详情：%s" % self.taskCenter)
        except Exception as err:
            log.error("任务分派异常:%s 任务信息：%s" % (err, self.taskCenter))
            # 策略任务启动异常
            self.taskCenter[1] = const.TASK_STATUS_EXCEPT
            for minitask in self.taskCenter[2]:
                if minitask[4] == const.TASK_STATUS_LOADING or minitask[4] == const.TASK_STATUS_RUNNING:
                    minitask[4] = const.TASK_STATUS_EXCEPT




